<template>
    <div class="body">
    <div class="banner">
      预约成功信息
    </div>
    <!-- <van-pull-refresh
      v-model="isLoading"
      @refresh="onRefresh"
      success-text="刷新成功"
    >
      <p>刷新次数: {{ count }}</p> -->
    <div class="sort">
      <ul>
        <li
          v-for="item in list"
          :key="item.id"
        >
          <img
            :src="item.portrait"
            class="imge"
            alt=""
          >
          <div class="name">{{item.username}}</div>
          <div class="number">{{item.phone | capitalize}}</div>
          <div class="end">
            <div class="time">{{item.applyTime | dateFormat}}</div>
            <div class="text">{{item.goodsName}}</div>
          </div>
        </li>
      </ul>
    </div>
    <!-- </van-pull-refresh> -->
    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
      <!-- <i class="iconfont icon-zhiding"></i> -->
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { Getlist } from '@/api/index'
import { share } from '../../js/wechat'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
import vueSeamlessScroll from "vue-seamless-scroll"; // 无缝滚动
import Vconsole from "vconsole";
const vConsole = new Vconsole();
export default {
  // 组件名称
  name: '',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      system: getSystem(),
      list: [],
      count: 0,
      isLoading: false,
      btnFlag: false,
      showTips: false,
      share: true,
      scrollTop: 0,
    }
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  filters: {
    // 手机号加密
    capitalize: function (value) {
      if (!value) return ''
      value = value.toString()
      return value.replace(/(\d{3})\d*(\d{2})/, "$1******$2")
    }
  },
  created () {
    this.Token()
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    window.addEventListener('scroll', this.scrollToTop)
  },
  // 组件方法
  methods: {
    // 获取token
    Token () {
      this.getToken(token => {
        this.$store.commit('getUser', token)
      })
      let that = this
      setTimeout(function () {
        that.NewList()
      }, 500)
    },
    getToken (callback) {
      const system = getSystem()
      if (system.android) {
        bridge.dsCall('getToken', '', res => {
          if (typeof res === 'string') res = JSON.parse(res)
          callback(res)
        })
        return
      }
      if (system.iOS) {
        bridge.iosReg('myTokenmethd', res => {
          const token = parseKeyValue(res)
          // const token = qs.parse(res)
          callback(token)
        })
        bridge.iosCall('getToken', '', res => { })
      }
    },
    // 获取信息
    NewList () {
      const tokened = this.$store.state.gettoken.token
      const system = getSystem()
      if (system.yfd) {
        if (tokened) {
          Getlist({
            activityGoodsId: 13
          }).then(res => {
            console.log(res);
            this.list = res.data.data
            // console.log(res.data.data.is_new_user);
            // this.$toast('成功！');
          }).catch(res => {
            console.log(res);
            console.log('失败');
          })
        }
      } else {
        this.$toast("请先登录APP！");
      }
    },
    onRefresh () {
      setTimeout(() => {
        this.$toast('刷新成功')
        this.isLoading = false;
        this.count++;
      }, 1000);
    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  // height: 160.066667rem;
  background: #f2f2f2;
  margin: 0 auto;
  line-height: 1.5;
  font-family: Arial, Helvetica;
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }
  .banner {
    width: 10rem;
    height: 2.133333rem;
    text-align: center;
    font-weight: 600;
    line-height: 2.133333rem;
    font-size: 0.48rem;
    color: #ffffff;
    background: -webkit-linear-gradient(left, #ff005e, #a1008c);
  }
  .sort {
    width: 9.626667rem;
    margin: 0.32rem auto;
    ul {
      li {
        width: 100%;
        border-radius: 0.266667rem;
        height: 1.946667rem;
        background: #ffffff;
        display: flex;
        .imge {
          width: 1.066667rem;
          height: 1.066667rem;
          border-radius: 0.8rem;
          margin-top: 0.453333rem;
          margin-left: 0.293333rem;
        }
        .name {
          width: 2.066667rem;
          height: 0.6rem;
          font-size: 0.373333rem;
          color: #000000;
          margin: auto 0.266667rem;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
        }
        .number {
          width: 2.266667rem;
          height: 0.6rem;
          margin: auto 0.066667rem;
          font-size: 0.373333rem;
        }
        .end {
          margin: auto 0.3rem;
          text-align: center;
          .time {
            font-size: 0.32rem;
            color: #9c9c9c;
          }
          .text {
            font-size: 0.373333rem;
            font-weight: 600;
            color: #000000;
          }
        }
      }
    }
  }
}
</style>
